package mysqlInit

import (
	"gin_chat_demo/global"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func InitMysql(dsn, jiangLaoDsn, csgoDsn string) {
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}
	jiangLaoDb, jiangLaoErr := gorm.Open(mysql.Open(jiangLaoDsn), &gorm.Config{})
	if jiangLaoErr != nil {
		panic("failed to connect jiangLao database")
	}
	csgoDb, csgoDbErr := gorm.Open(mysql.Open(csgoDsn), &gorm.Config{})
	if csgoDbErr != nil {
		panic("failed to connect jiangLao database")
	}

	global.DB = db
	global.JiangLaoDB = jiangLaoDb
	global.CsgoDB = csgoDb
}
